<?php

namespace app\health\behavior;

use app\health\service\UserApiLogService;
use think\response\Json;

class AppListener
{
    /**
     * 模块初始化
     * @param $params
     * @return void
     */
    public function moduleInit(&$params): void
    {
        debug('health_run_start');
    }

    /**
     * 输出结束
     * @param $params
     * @return void
     */
    public function responseEnd(&$params): void
    {
        debug('health_run_end');
        $responseCode = 0;
        $response     = '';
        if ($params instanceof Json) {
            $data         = $params->getData();
            $responseCode = $data['code'] ?? 0;
            $response     = $params->getContent();
        }
        UserApiLogService::record($response, $responseCode);
    }
}